﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using LGSVR.Common;
using System.Data;

namespace LGSVR.BLL.Sys
{
    public class CompanyBLL
    {
        public bool IsHasCompanyIDID(string companyID, int id)
        {
            string sql = "select count(*) from company where state=1 and [companyID]=@companyID";
            if (id != 0)
            {
                sql += " and id!=@ID";
            }
            List<SqlParameter> lstParam = new List<SqlParameter>();
            lstParam.Add(new SqlParameter("@companyID", companyID));
            lstParam.Add(new SqlParameter("@ID", id));

            int len = Convert.ToInt32(SQLHelper.GetScale(sql, System.Data.CommandType.Text, lstParam.ToArray()));
            return len > 0;
        }

        public string GetNameByCompanyID(string companyID)
        {
            string sql = "select companyName from company where companyID=@companyID ";
            List<SqlParameter> lstParam = new List<SqlParameter>();
            lstParam.Add(new SqlParameter("@companyID", companyID));
            object companyName = SQLHelper.GetScale(sql, System.Data.CommandType.Text, lstParam.ToArray());
            return companyName==null?"":companyName.ToString();
        }

        public DataTable GetCompanyList(string companyName)
        {
            string sql = "select * from company where state=1 ";
            if (companyName != "")
            {
                sql += " and companyName!=@companyName";
            }
            List<SqlParameter> lstParam = new List<SqlParameter>();
            lstParam.Add(new SqlParameter("@companyName", companyName));
            DataTable dt = SQLHelper.GetDataTable(sql, CommandType.Text, lstParam.ToArray());
       
            return dt;
        }
    }
}
